/**
 * 
 */
package com.livemeter;


import com.livemeter.R;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;


/**
 *
 *Activity for logging in
 */
public class SplashScreenActivity extends Activity 
{
	private static boolean appStartedFirstTime = false;
	private boolean doNotStartLoginActivity = false;
	
	public static boolean getAppStartedFirstTime()
	{
		return SplashScreenActivity.appStartedFirstTime;
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {   		
        super.onCreate(savedInstanceState);
        
        //show activity in full screen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        
        
        setContentView(R.layout.splash_activity);  
        
        Bundle extras = getIntent().getExtras();     
        if((extras != null) && extras.getBoolean("ignoreAppConfig")) //splash screen will be shown until user clicks
        {
        	this.doNotStartLoginActivity = true;
        	return;
        }
        
        //load flag to check whether app is started first time
        SharedPreferences settings = getSharedPreferences("LoginSettings", 0);
		appStartedFirstTime = settings.getBoolean("AppStartedFirstTime", true);
		
        //show splash screen only if app is opened first time
       /*//always show splash screen now
        *  if(!appStartedFirstTime)
        {
        	//close splash screen on touch and go to login activity
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(SplashScreenActivity.this, LoginActivity.class.getName());
            startActivity(intent);  
        	
        	this.finish();
        }
        else //save flag to signal that app started first time
        {
        			
    		SharedPreferences.Editor editor = settings.edit();
    		editor.putBoolean("AppStartedFirstTime", false);
    		// Commit the edits!
    		editor.commit();
        }*/
        	
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
    	if(!this.doNotStartLoginActivity)
    	{
    		//close splash screen on touch and go to login activity
    		Intent intent = new Intent(Intent.ACTION_VIEW);
        	intent.setClassName(SplashScreenActivity.this, LoginActivity.class.getName());
        	startActivity(intent);  
    	}
    	
    	this.finish();
    	
    	return true;
    }
    
}

